import { getLocalToken, removeLocalToken, setLocalToken } from '@/utils/auth'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('hm-user',()=>{
    // 优先从本地取
    const token = ref(getLocalToken() || '') 
    const setToken = (t: string)=>{
      token.value = t
      // 本地存一份
      setLocalToken(t)
    }
    // 消除用户信息
    const clearUserInfo = ()=>{
      token.value = ''
      //将本地数据也要消除
      removeLocalToken()
    }
    return { token, setToken, clearUserInfo }
})